package com.his.struts.dao.help;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import com.his.struts.form.ConnectForm;
import com.his.struts.form.FoodForm;
import com.his.struts.util.DbUtil;

/**
 * “帮助”持久层
 * 
 * @author mlxnle
 * 
 */
public class ConnectsImp implements ConnectsDao {
	Logger log = Logger.getLogger(ConnectsImp.class);
	DbUtil db = new DbUtil();
	ResultSet rs = null;

	/**
	 * 显示联系方式
	 * 
	 * @return ConnectForm 联系方式form
	 */
	public ConnectForm getShowCon() {
		ConnectForm connectForm = new ConnectForm();
		String sql = "select * from connectus";
		rs = db.executeQuery(sql, null);
		try {
			while (rs.next()) {
				connectForm.setHid(rs.getInt("hid"));
				connectForm.setPhone(rs.getString("phone"));
				connectForm.setAddress(rs.getString("address"));
				connectForm.setBusLine(rs.getString("busLine"));
				connectForm.setAddimg(rs.getString("addimg"));
			}
			;
		} catch (SQLException e) {
			log.error(e.getMessage());
		} finally {
			db.closeAll();
		}
		return connectForm;
	}

	/**
	 * 更新联系方式
	 * 
	 * @param connectForm
	 *            联系方式form
	 * @return boolean 是否更新
	 */
	public boolean updateCon(ConnectForm connectForm) {
		Boolean ok = false;
		String phone = connectForm.getPhone();
		String address = connectForm.getAddress();
		String busLine = connectForm.getBusLine();
		String sql = "update connectUs set  phone = ?,address=?,busLine=? where hid = 1";
		ArrayList list = new ArrayList();
		list.add(phone);
		list.add(address);
		list.add(busLine);
		int line = db.executeUpdate(sql, list);
		if (line != 0) {
			ok = true;
		}
		db.closeAll();
		return ok;
	}

	/**
	 * 更新图片
	 * 
	 * @param connectForm
	 *            联系方式form
	 * @return boolean 是否更新
	 */
	public boolean updateImg(ConnectForm connectForm) {
		Boolean ok = false;
		String addimg = connectForm.getAddimg();
		String sql = "update connectUs set addimg=? where hid = 1";
		ArrayList list = new ArrayList();
		list.add(addimg);
		int line = db.executeUpdate(sql, list);
		if (line != 0) {
			ok = true;
		}
		db.closeAll();
		return ok;
	}

}
